﻿
#ifndef SYMBOL_TABLE_H_369C5E3D5CEFC5D0
#define SYMBOL_TABLE_H_369C5E3D5CEFC5D0  1

#include "n2base.h"
#include "Coff.h"
#include "UniverTab.h"
#include "HashTable.h"

class CoffRelInfoEntry
{
public:
    n2u32       va;
    n2u32       sym_index;
    n2u16       type;

    CoffRelInfoEntry() {
        va = 0;
        sym_index = 0;
        type = 0;
    }
};


class Symbol : public UniverTabItem
{
public:
    N2PoolString        m_symbolName;
    union {
        Coff32_Symb             base;
        Coff32_AuxSymFuncDef    funcdef;
        Coff32_AuxSymFuncBfEf   funcbfef;
        Coff32_AuxSymWeak       weakinfo;
        Coff32_AuxSymFile       file;
        Coff32_AuxSymSectionDef sectiondef;
        Coff32_AuxSymClr        clrinfo;
    }sym;
    unsigned int        m_globalSectionId;                  // section ID of linker-name-space
    n2u8                m_extType;                          // 0:global, 1:comdat, 2:weak, 3:common, 4:static
    bool                m_isAuxSym;                         // is an Aux Symbol
    n2u8                m_auxtype;                          // the Aux Symbol type

    ///// use for same name symbol ////
    bool                m_boSameNameSym;                    // if this is a same name symbol record, m_boSameNameSym==true
    Symbol *            m_next;                             // point to same name symbol list, if next==NULL, no same name symbol
    /////////

    Symbol();
    Symbol(const Coff32_Symb *pCoff32Symbol, const char * name);
    virtual ~Symbol();
    virtual void moveFrom(UniverTabItem *p);
    virtual void copyFrom(const UniverTabItem *p);
    virtual UniverTabItem * getOffsetItem(size_t index);
    const char* getStr();
};

class SymbolTable : public UniverTab
{
protected:
    //TN2HashTable *          hashtble;
    static const char* sfGetSymbolName(void* object, size_t index);
    static bool sfCmpSymbolName(const unsigned char* pbData1, const unsigned char* pbData2);
protected:
    virtual UniverTabItem* allocGroupData(size_t count);
public:
    Symbol* getSymbol(size_t index);
    SymbolTable(size_t  groupCubage);
    SymbolTable();
};


extern SymbolTable * global_syms;
extern SymbolTable * comdat_syms;
extern SymbolTable * weak_syms;

#endif // SYMBOL_TABLE_H_369C5E3D5CEFC5D0





